package com.iweb.controller;

import com.common.context.RequestMapping;
import com.common.model.DataGrid;
import com.common.model.Page;
import com.iweb.pojo.Order;
import com.iweb.service.OrderService;
import com.iweb.utils.JsonUtil;

import javax.servlet.http.HttpServletResponse;

@RequestMapping("order")
public class OrderController {

    @RequestMapping("findOrderList")
    // findOrderList
    public String findOrderList(Page page, HttpServletResponse response) {
        OrderService orderService = new OrderService();
        DataGrid<Order> dataGrid = orderService.findOrderList(page);
        JsonUtil.writeJsonStr(response,dataGrid);
        return null;
    }

    @RequestMapping("findOrderNopay")
    // findOrderNopay
    public String findOrderNopay(Page page, HttpServletResponse response) {
        OrderService orderService = new OrderService();
        DataGrid<Order> dataGrid = orderService.findOrderNopay(page);
        JsonUtil.writeJsonStr(response,dataGrid);
        return null;
    }

    @RequestMapping("findOrderPayed")
    // findOrderPayed
    public String findOrderPayed(Page page, HttpServletResponse response) {
        OrderService orderService = new OrderService();
        DataGrid<Order> dataGrid = orderService.findOrderPayed(page);
        JsonUtil.writeJsonStr(response,dataGrid);
        return null;
    }

    @RequestMapping("addOrder")
    // addUser
    public String addOrder(Order order) {
        OrderService orderService = new OrderService();
        boolean flag = orderService.addOrder(order);
        if (flag) {
            // 注冊成功  indexAdmin.jsp
            return "/order/order.jsp";
        } else {
            // 如果重複返 indexAddAdmin.jsp
            return "/order/AddOrder.jsp";
        }
    }
    @RequestMapping("apply")
    public String updateById(Order order){
        OrderService orderService = new OrderService();
        orderService.apply(order.getOrder_id());
        return "/order/order.jsp";
    }
}
